<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div>
	<form id="infoForm" target="hiddenFrame" action="${path}/mc/usersaveMemberInfo" method="post" enctype="multipart/form-data">
		<input type="hidden" name="entity.id" value="${entity.id}" id="uId" />
		<fieldset style="padding-left: 10px;">
			<table>
			  	<tr>
			  		<td>帐号</td>
			  		<td>
			  			<input type="text" name="entity.account" value="${entity.account}" onchange="checkAccount(this)" class="{required:true,number: true,min:1,messages:{required:'帐号不能为空',number:'请输入正确的手机号码'}}"/>
			  		</td>
			  	</tr>
				<%-- <tr>
			  		<td>头像</td>
			  		<td>
			  			<c:import url="/mc/common/imgPreview.jsp?hidName=entity.headPortrait.id&name=headPortrait.file&imgPath=${entity.headPortrait.picName}${entity.headPortrait.picSuffix}&picId=${entity.headPortrait.id}&index=1&required=true" />
			  		</td>
			  	</tr> --%>
			  	<tr>
			  		<td>昵称</td>
			  		<td>
			  			<input type="text" name="entity.name" value="${entity.name}" class="{required:true,messages:{required:'请输入昵称'}}" />
			  		</td>
			  	</tr>
			  	<tr>
			  		<td>性别</td>
			  		<td>
			  			<select name="entity.sex" dir="${entity.sex}" >
			  				<option value="1">男</option>
		  					<option value="2">女</option>
						</select>
			  		</td>
			  	</tr>
		  		<tr>
			  		<td>联系电话</td>
			  		<td>
			  			<input type="text" name="entity.phone" value="${entity.phone}" class="{required:true,messages:{required:'请输入联系电话'}}"/>
			  		</td>
			  	</tr>
			  	<tr>
			  		<td>密码</td>
			  		<td>
			  			<input type="password" style="display: none;" />
			  			<input id="txtPwd" autocomplete="off" type="password" name="entity.password" <c:if test="${empty entity.id}">class="{required:true,messages:{required:'请输入密码'}}"</c:if> />
			  		</td>
			  	</tr>
				<tr>
			  		<td>确认密码</td>
			  		<td>
			  			<input type="password" 
				  			<c:choose>
				  				<c:when test="${empty entity.id}">class="{required:true, equalTo:'#txtPwd', messages:{required:'请确认密码', equalTo:'密码不一致'}}"</c:when>
				  				<c:otherwise>class="{equalTo:'#txtPwd', messages:{equalTo:'密码不一致'}}"</c:otherwise>
				  			</c:choose> />
			  		</td>
			  	</tr>
			  	<%-- <tr>
			  		<td>地址</td>
			  		<td>
			  			<input type="text" name="entity.address" value="${entity.address}" class="{required:true,messages:{required:'请输入联系地址'}}"/>
			  		</td>
			  	</tr> --%>
		   </table>
		</fieldset>
	</form>
</div>


<script type="text/javascript">
	var flag=true;//校验帐号唯一性
	function checkAccount(text){
		var tel = text.value;
		/* var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
		if(telReg==false){//不符合手机号码格式
			flag=false;
			hiAlert("请填写正确的手机号!","提示");
			return false;
		}else{
			flag=true;
		} */
		if(tel!=null&&tel!=""){
			$.ajax({
				url:"${path}/mc/useronlyAccount",
				data:{"entity.account":tel,"id":$("#uId").val()},
				type:"post",
				success:function(data){
					if(data.flag==0){
						flag=false;
						hiAlert("帐号"+tel+"已存在!请重新输入!","提示");
						return false;
					}else{
						flag=true;
					}
				}
			});
		}
	}
	//提交前再校验帐号唯一性
	$("#infoForm").validate({
	    submitHandler: function(form) {
	    	if(flag==false){
	    		hiAlert("该帐号已存在,请重新输入!","提示");
	    		return false;
	    	}
	    	form.submit();
	    }
	});
</script>
